import * as types from './type';
import {fromJS} from "immutable";

const defaultData = fromJS({
    userName: '',
    password: '',
    signForm: {
        userName: '',
        password: '',
        surePassword: '',
        phone: '',
        email: '',
        smsCode: '',
        mailCode: '',
    }
})

//eslint-disable-next-line
export default (state = defaultData, action) => {
    let newVal = action.value;
    if (newVal !== undefined) {
        switch (action.type) {
            case types.LOGIN_INPUT_ACCOUNT:
                return state.set('userName', newVal);
            case types.LOGIN_INPUT_PASSWORD:
                return state.set('password', newVal);
            case types.SIGN_INPUT_ACCOUNT:
                return state.setIn(['signForm', 'userName'], newVal);
            case types.SIGN_INPUT_PASSWORD:
                return state.setIn(['signForm', 'password'], newVal);
            case types.SIGN_INPUT_SURE_PASSWORD:
                return state.setIn(['signForm', 'surePassword'], newVal);
            case types.SIGN_INPUT_PHONE:
                return state.setIn(['signForm', 'phone'], newVal);
            case types.SIGN_INPUT_EMAIL:
                return state.setIn(['signForm', 'email'], newVal);
            case types.SIGN_INPUT_SMS_CODE:
                return state.setIn(['signForm', 'smsCode'], newVal);
            case types.SIGN_INPUT_MAIL_CODE:
                return state.setIn(['signForm', 'mailCode'], newVal);
            default:
                return state;
        }
    }
    return state;
}
